package com.example.company

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.company.databinding.ActivityCompanyDetailBinding
import com.example.company.vm.CompanyViewModel
import com.example.image.glide.GlideImgLoader
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/company/CompanyDetailActivity")
class CompanyDetailActivity : BaseMvvmActivity<ActivityCompanyDetailBinding>() {

    @Autowired
    @JvmField
    var id:Int = 0

    private val detailViewModel:CompanyViewModel by viewModels()

    override fun initView() {
        ARouter.getInstance().inject(this)
        detailViewModel.getCompanyDetail(id)
        detailViewModel.mCompanyDetailSuccess.observe(this){
            mDataBinding.cName.text = it.name
            mDataBinding.cType.text = it.industryType
            mDataBinding.cAddress.text = it.address
            mDataBinding.cStockName.text = it.stockName
            mDataBinding.cPhone.text = it.contactInfo
            mDataBinding.cStatus.text = it.status
            mDataBinding.cStockCode.text = it.stockCode
            mDataBinding.cUsername.text = it.legalRepresentative
            if(it.listed){
                mDataBinding.cListed.text = "是"
            }else{
                mDataBinding.cListed.text = "否"
            }
            GlideImgLoader.loadImage(this,"https://cn.bing.com/images/search?q=%e4%bc%81%e4%b8%9a%e7%ae%a1%e7%90%86%e5%9b%be%e7%89%87&id=AC38DF51276B2F4DDC10AD17ED42F48EE09242AE&FORM=IACFIR",mDataBinding.cPhotos)
            ToastUtils.showLong("显示成功")
        }
        detailViewModel.mError.observe(this){
            ToastUtils.showLong("显示失败")
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_company_detail
}